#ifndef CVX_SF_H
#define CVX_SF_H 1

//static function in OpenCV

#include "cvxImage.h"
#include <vector>
#include <utility>
#include <string>
#include <stdio.h>
#include <map>

using std::vector;
using std::pair;
using std::string;
using std::map;


class CvxSF
{
public:
	//store image sequence in a .
	static void saveImageVec(vector<IplImage*>& image, string prefix = string("left"), 
							 string suffix = string(".png"), const char* dirctory = "store_img\\");
	//release image memory
	static void releaseImage(vector<IplImage*>& inoutImg);

	//get chessboard from an image
	static bool GetChessboard(IplImage *inImage, bool accurate, const CvSize &size,vector<Point2f> &pts);	

	//get insider points of a chessboard image
	static bool GetInsidePoints(IplImage *grayImage, vector<Point2f> &extremeCorners, 
								const CvSize &patternSize, vector<Point2f> &corners, bool subpixel);

	//find and save chessboard points in a image sequence
	static void findSaveChessboard(const vector<IplImage*> imageVec, FILE *pf, const CvSize &size, bool checkUpdown);
	static void loadChessboard(FILE *pf, vector<int> &idx, vector<vector<Point2f> > &chessboardPos, CvSize &size);
	
	//store chessboard position to file
	static void findSaveChessboard(const string &videoFileName, const string &savefileName, 
								   const CvSize& size, bool checkUpdown);
	static void saveChessboard(const string &videoFileName, const string &savefileName, 
							   const vector<vector<Point2f>>&pts, const CvSize &size);

	//load chessboard from saved file
	static void loadChessboard(const string &fileName, string &videoFileName, vector<int> &idx, vector<vector<Point2f> > &chessboardPos, CvSize &size);

	//store stereo image chessboard
	static void saveStereoChessboard(const string &videoLeft, const string &videoRight, const string &saveFileName, 
									 int step, const CvSize &size, bool checkUpdown);
	static void loadStereoChessboard(const string &fileName, string &leftVideo, string &rightVideo,									
									 vector<int> &idx, CvSize &size, vector<vector<Point2f>> &leftPts, 
									 vector<vector<Point2f>> &rightPts);

	//solve AX = b, b != 0
	static bool LeastSquare(const vector<map<int, double> > &matrix_vec, 
							const vector<double> & right_vec, vector<double> &result);

};	
	

#endif